package in.animeshpathak.saferstreets;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

public class Utils {
	/**
	 * renders a velocity template on the response
	 * @param filename The template file path
	 * @param resp the HTTP response object
	 * @param context the velocity context
	 */
	public static void renderTemplate(String filename, HttpServletResponse resp, VelocityContext context) throws IOException{
		resp.setContentType("text/plain");

		//this should show the upload form.

		/*  first, get and initialize an engine  */
		VelocityEngine ve = new VelocityEngine();

		//TODO change to appengine logger?
		ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");

		ve.init();
		/*  next, get the Template  */
		Template t = ve.getTemplate(filename);

		/* now render the template into a Writer */
		resp.setContentType("text/html");

		t.merge( context, resp.getWriter());		
	}

}
